
import com.itheima.controller.UserController;
import com.itheima.domain.po.User;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.*;

/**
 * @author zhanliuzhu
 * @date 2023/10/30
 * @Description
 */
@SpringBootTest
public class text {

    @Autowired
    UserController userController;


    @Test
    public void text1() {
        System.out.println("你好");
    }


    @Test
    public void aaa() {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                System.out.println("你好");
            }
        };
        //启动线程
        runnable.run();
    }


    /**
     * 各种集合对比
     */
    @Test
    public void listText() {
        //ArrayList
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(3);
        arrayList.add(15);
        arrayList.add(15);
        arrayList.add(2);
        System.out.println("arralist的结果：" + arrayList);
        //LinkedList
        LinkedList<Integer> linkedList = new LinkedList<>();
        linkedList.add(5);
        linkedList.add(2);
        linkedList.add(2);
        linkedList.add(8);
        System.out.println("linkedList的结果：" + linkedList);
        //HashSet
        HashSet<Integer> hashSet = new HashSet<>();
        hashSet.add(9);
        hashSet.add(6);
        hashSet.add(6);
        hashSet.add(12);
        System.out.println("hashSet的结果："+hashSet);
        //LinkedHashSet
        LinkedHashSet<Integer> linkedHashSet = new LinkedHashSet<>();
        linkedHashSet.add(8);
        linkedHashSet.add(6);
        linkedHashSet.add(6);
        linkedHashSet.add(12);
        System.out.println("linkedHashSet的结果："+linkedHashSet);
        //TreeSet
        TreeSet<Integer> treeSet = new TreeSet<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        treeSet.add(8);
        treeSet.add(16);
        treeSet.add(5);
        treeSet.add(16);
        System.out.println("TreeSet的实现结果："+treeSet);
    }


    /**
     * TreeMap使用、排序
     */
    @Test
    public void treeMap(){
        TreeMap<Integer, String> treeMap = new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1-o2;
            }
        });
        treeMap.put(1,"老吕");
        treeMap.put(2,"老刘");
        treeMap.put(3,"老上");
        System.out.println(treeMap);
    }

    /**
     * HashMap存储对象
     */
    @Test
    public void hashMap(){
        HashMap<Long, User> longUserHashMap = new HashMap<>();
        User user = new User();
        user.setAge(18);
        user.setName("张三");
        user.setId(3L);
        longUserHashMap.put(user.getId(),user);
        System.out.println(longUserHashMap.get(user.getId()));
    }





}
